﻿using DataAccess;
using DTO;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAO
{
    public class LoaiDaiLyDAO
    {
        public static List<LoaiDaiLyDTO> LoadDanhSachLoaiDaiLy()
        {
            List<LoaiDaiLyDTO> list = new List<LoaiDaiLyDTO>();
            string query = "SELECT * FROM LOAIDAILY";
            DataTable dt = DataConnection.ExecQuery(query);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    LoaiDaiLyDTO dd = new LoaiDaiLyDTO();
                    dd.MaLoaiDaiLy = Convert.ToInt64(dr["MaLoaiDaiLy"]);
                    dd.TenLoaiDaiLy = dr["TenLoaiDaiLy"].ToString();
                    dd.NoToiDa = Convert.ToInt64(dr["NoToiDa"]);
                    list.Add(dd);
                }
            }
            return list;
        }

        public static DataTable LayTienNo(string p)
        {
            string query = "SELECT a.NoToiDa FROM LOAIDAILY a join DAILY b on a.MaLoaiDaiLy = b.MaLoaiDaiLy where b.MaDaiLy = '"+p+"'";
            DataTable dt = DataConnection.ExecQuery(query);
            return dt;
        }
    }
}
